home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 February: Tool Chest / Dev.CD Feb 00 TC.toast / pc / tool chest / development kits / hypercard related / xcmds & xfcns / byrne's xcmds&xfcns / source / setspeakervol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-28  |  3.4 KB  |  141 lines

  1. /*
  2.     SetSpeakerVol XCMD v1.1
  3.     
  4.     ©1991 Apple Computer, Inc.; by Mike Byrne
  5.     
  6.     This XCMD may be used to set the speaker volume, just as if in the Control Panel.  It is easy to change 
  7.     the volume with a simple toolbox call, but changing the parameter RAM so that the Control Panel knows 
  8.     about it is a little trickier.  Watch carefully...
  9.     
  10.     Form:
  11.     SetSpeakerVol <volume>
  12.     
  13.     # the MPW 3.2 build commands:
  14.     C -b SetSpeakerVol.c 
  15.         Link -w -t STAK -c WILD -rt XCMD=611 ∂
  16.             -m ENTRYPOINT ∂
  17.             -sg SetSpeakerVol ∂
  18.             SetSpeakerVol.c.o ∂
  19.             "{Libraries}HyperXLib.o" ∂
  20.             "{Libraries}Runtime.o" ∂
  21.             "{Libraries}Interface.o" ∂
  22.             "{CLibraries}StdCLib.o" ∂
  23.             -o "teststack"
  24. */
  25.  
  26. #include <Types.h>
  27. #include <Sound.h>
  28. #include <string.h>
  29. #include <Memory.h>
  30. #include <SysEqu.h>
  31. #include "HyperXCmd.h"
  32.  
  33. #define NULL (long) 0
  34. #define NIL (long) 0
  35.  
  36. #define kNumParams 1
  37.  
  38.  
  39. /* prototypes */
  40. void ErrorBack(XCmdPtr paramPtr, char *message);
  41. void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
  42. void UnlockParams  ( XCmdPtr paramPtr, short paramCount );
  43.  
  44.  
  45. pascal void EntryPoint(XCmdPtr paramPtr)
  46. {
  47.     /* variable declarations */
  48.     long    volNum;
  49.     Byte*    pRam;
  50.     char    volString[10];
  51.  
  52.  
  53.     /* move high and lock the parameters. */
  54.     MoveLockParams(paramPtr, paramPtr->paramCount);
  55.  
  56.     /* check for copyright or syntax help request */
  57.     if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
  58.         ErrorBack(paramPtr, "v1.1, ©1991 Apple Computer, Inc.; by Mike Byrne");
  59.         UnlockParams(paramPtr, paramPtr->paramCount);
  60.         return;
  61.     } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
  62.         ErrorBack(paramPtr, "SetSpeakerVol syntax is 'SetSpeakerVol <volume>'");
  63.         UnlockParams(paramPtr, paramPtr->paramCount);
  64.         return;
  65.     }
  66.  
  67.     /* not a copyright or help request.       */     
  68.     /* check for correct number of parameters */
  69.     if (paramPtr->paramCount != kNumParams) {
  70.         ErrorBack(paramPtr, "Error: SetSpeakerVol syntax is 'SetSpeakerVol <volume>'");
  71.         UnlockParams(paramPtr, paramPtr->paramCount);
  72.         return;
  73.     }
  74.  
  75.     /* this is the real thing.  Convert the parameter to a pascal string, then that to a number. */
  76.     strcpy(volString, (char*) *paramPtr->params[0]);
  77.     c2pstr(volString);
  78.     StringToNum(volString, &volNum);
  79.     if (volNum < 0 ) { volNum = 0; }
  80.     if (volNum > 7 ) { volNum = 7; }
  81.     
  82.     /* Now, set the volume from the toolbox, set the address of the byte, and set the byte of pRAM. */
  83.     SetSoundVol( (short) volNum);
  84.     (long) pRam = SPVolCtl;
  85.     *pRam = (Byte) volNum;
  86.  
  87.     /* we're done. */
  88.     UnlockParams(paramPtr, paramPtr->paramCount);
  89.     return;
  90.  
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.     
  98. /* allocate and load up paramPtr->returnValue with a string 
  99.    -------------------------------------------------------- */
  100. void ErrorBack(XCmdPtr paramPtr, char *message)
  101. {
  102.     Handle  mesHnd;
  103.  
  104.     /*
  105.         Allocate space for an error message.
  106.         Copy the string into it.
  107.         Return the handle to HyperCard.
  108.     */
  109.     mesHnd = NewHandle((long)(strlen(message)+1));
  110.     if (mesHnd == nil) return;
  111.     strcpy((char *)*mesHnd,message);
  112.     paramPtr->returnValue = mesHnd;
  113. }
  114.  
  115.  
  116.  
  117. /*  move high and lock down all parameters  
  118.     ----------------------------------------------------------------------- */
  119. void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
  120. {
  121.     short i;
  122.     
  123.     for(i=0; i <= paramCount-1; i++)
  124.     {
  125.         MoveHHi(paramPtr->params[i]);
  126.         HLock(paramPtr->params[i]);
  127.     }
  128. }
  129.  
  130.  
  131.  
  132.  
  133. /* unlock all parameter handles in the XCmdBlock  
  134.    ---------------------------------------------  */
  135. void UnlockParams  ( XCmdPtr paramPtr, short paramCount )
  136. {    short i;
  137.     
  138.     for(i=0; i <= paramCount-1; i++)
  139.         { HUnlock(paramPtr->params[i]);}
  140. }
  141.